<%@ page language="java" contentType="text/html; charset=utf-8" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%
    JSONObject jsonData = new JSONObject();
    User user = HrmUserVarify.getUser(request, response);
    int userid = user.getUID();
    String sql = "SELECT\n" +
            "\tcount( * ) \n" +
            "FROM\n" +
            "\t(\n" +
            "SELECT\n" +
            "\tsysid,\n" +
            "\tappurl,\n" +
            "\ttakisremark,\n" +
            "\trequestmark,\n" +
            "\trequestid,\n" +
            "\tcreatedate,\n" +
            "\tcreatetime,\n" +
            "\tcreater,\n" +
            "\tcreatertype,\n" +
            "\tworkflowid,\n" +
            "\trequestname,\n" +
            "\tSTATUS,\n" +
            "\trequestlevel,\n" +
            "\tcurrentnodeid,\n" +
            "\treceivedate,\n" +
            "\treceivetime,\n" +
            "\tviewtype,\n" +
            "\tisremark,\n" +
            "\tuserid,\n" +
            "\tnodeid,\n" +
            "\tagentorbyagentid,\n" +
            "\tagenttype,\n" +
            "\tisprocessed,\n" +
            "\tsystype,\n" +
            "\tworkflowtype,\n" +
            "\tviewDate,\n" +
            "\tviewTime,\n" +
            "\tlastFeedBackDate,\n" +
            "\tlastFeedBackTime,\n" +
            "\tneedwfback,\n" +
            "\tlastFeedBackOperator,\n" +
            "\toperatedate,\n" +
            "\toperatetime,\n" +
            "\toperatedateNew,\n" +
            "\toperatetimeNew,\n" +
            "\tisbereject,\n" +
            "\tnodename \n" +
            "FROM\n" +
            "\t(\n" +
            "SELECT\n" +
            "\t0 AS sysid,\n" +
            "\tt1.requestid AS appurl,\n" +
            "\tt2.takisremark,\n" +
            "\tt1.requestmark,\n" +
            "\tt1.requestid,\n" +
            "\tt1.createdate,\n" +
            "\tt1.createtime,\n" +
            "\tt1.creater,\n" +
            "\tt1.creatertype,\n" +
            "\tt1.workflowid,\n" +
            "\tt1.requestname,\n" +
            "\tt1.STATUS,\n" +
            "\tt1.requestlevel,\n" +
            "\tt1.currentnodeid,\n" +
            "\tt2.receivedate,\n" +
            "\tt2.receivetime,\n" +
            "\tt2.viewtype,\n" +
            "\tt2.isremark,\n" +
            "\tt2.userid,\n" +
            "\tt2.nodeid,\n" +
            "\tt2.agentorbyagentid,\n" +
            "\tt2.agenttype,\n" +
            "\tt2.isprocessed,\n" +
            "\t0 AS systype,\n" +
            "\tt2.workflowtype,\n" +
            "\tt2.viewDate,\n" +
            "\tt2.viewTime,\n" +
            "\tt1.lastFeedBackDate,\n" +
            "\tt1.lastFeedBackTime,\n" +
            "\tt2.needwfback,\n" +
            "\tt1.lastFeedBackOperator,\n" +
            "\t( CASE WHEN t2.operatedate IS NULL THEN t2.receivedate ELSE t2.operatedate END ) operatedate,\n" +
            "\t( CASE WHEN t2.operatetime IS NULL THEN t2.receivetime ELSE t2.operatetime END ) operatetime,\n" +
            "\tt2.operatedate AS operatedateNew,\n" +
            "\tt2.operatetime AS operatetimeNew,\n" +
            "\tt2.isbereject,\n" +
            "\t'' AS nodename \n" +
            "FROM\n" +
            "\tworkflow_requestbase t1,\n" +
            "\tworkflow_base t3,\n" +
            "\tworkflow_currentoperator t2 \n" +
            "WHERE\n" +
            "\tt2.userid IN ( "+userid+" ) \n" +
            "\tAND t2.usertype = 0 \n" +
            "\tAND t2.islasttimes = 1 \n" +
            "\tAND t1.requestid = t2.requestid \n" +
            "\tAND ( t1.deleted <> 1 OR t1.deleted IS NULL OR t1.deleted = '' ) \n" +
            "\tAND (\n" +
            "\tifnull( t1.currentstatus,- 1 ) = - 1 \n" +
            "\tOR ( ifnull( t1.currentstatus,- 1 ) = 0 AND t1.creater IN ( "+userid+" ) ) \n" +
            "\t) \n" +
            "\tAND t1.workflowid = t3.id \n" +
            "\tAND t3.isvalid IN ( '1', '3' ) \n" +
            "\tAND ( ( t1.workflowid IN ( 45 ) ) ) \n" +
            "\tAND (\n" +
            "\tt2.isremark IN ( '1', '5', '8', '9', '7', '11' ) \n" +
            "\tOR t2.isremark = '0' \n" +
            "\tAND ( takisremark IS NULL OR takisremark = 0 ) \n" +
            "\t) \n" +
            "\tAND t2.islasttimes = 1 \n" +
            "\tAND ( t2.isprocessing = '' OR t2.isprocessing IS NULL ) \n" +
            "\tAND t3.isvalid IN ( '1', '3' ) UNION\n" +
            "\t(\n" +
            "SELECT\n" +
            "\tsysid,\n" +
            "\trequestid AS appurl,\n" +
            "\t0 AS takisremark,\n" +
            "\t'' AS requestmark,\n" +
            "\trequestid,\n" +
            "\tcreatedate,\n" +
            "\tcreatetime,\n" +
            "\tcreatorid AS creater,\n" +
            "\t0 AS creatertype,\n" +
            "\tworkflowid,\n" +
            "\trequestname,\n" +
            "\t'' AS STATUS,\n" +
            "\trequestlevel,\n" +
            "\t0 AS currentnodeid,\n" +
            "\treceivedate,\n" +
            "\treceivetime,\n" +
            "\tviewtype,\n" +
            "\tisremark,\n" +
            "\tuserid,\n" +
            "\t0 AS nodeid,\n" +
            "\t- 1 AS agentorbyagentid,\n" +
            "\t'0' AS agenttype,\n" +
            "\t'0' AS isprocessed,\n" +
            "\t1 AS systype,\n" +
            "\tsysid AS workflowtype,\n" +
            "\t'' AS viewDate,\n" +
            "\t'' AS viewTime,\n" +
            "\t'' AS lastFeedBackDate,\n" +
            "\t'' AS lastFeedBackTime,\n" +
            "\t'' AS needwfback,\n" +
            "\t0 AS lastFeedBackOperator,\n" +
            "\t( CASE WHEN operatedate IS NULL THEN receivedate ELSE operatedate END ) operatedate,\n" +
            "\t( CASE WHEN operatetime IS NULL THEN receivetime ELSE operatetime END ) operatetime,\n" +
            "\toperatedate AS operatedateNew,\n" +
            "\toperatetime AS operatetimeNew,\n" +
            "\t'0' AS isbereject,\n" +
            "\tnodename \n" +
            "FROM\n" +
            "\tofs_todo_data \n" +
            "WHERE\n" +
            "\t1 = 1 \n" +
            "\tAND ( ( workflowid IN ( 45 ) ) ) \n" +
            "\tAND islasttimes = 1 \n" +
            "\tAND isremark IN ( 0, 8, 9 ) \n" +
            "\tAND workflowid IN ( SELECT workflowid FROM ofs_workflow WHERE ( cancel = 0 OR cancel IS NULL ) ) \n" +
            "\tAND userid IN ( "+userid+" ) \n" +
            "\tAND pcurl IS NOT NULL \n" +
            "\tAND pcurl <> '' \n" +
            "\tAND workflowid IN ( SELECT workflowid FROM ofs_workflow WHERE ( cancel = 0 OR cancel IS NULL ) ) \n" +
            "\t) \n" +
            "\t) t1 \n" +
            "\t) t2 \n" +
            "ORDER BY\n" +
            "\treceivedate DESC,\n" +
            "\treceivetime DESC";
    rs.executeQuery( sql );
    rs.next();
    int count = Util.getIntValue(rs.getString( 1 ));
    jsonData.put( "count", count );
    out.print( jsonData.toJSONString() );
%>
